#include<iostream>
#include<map>
using namespace std;
bool validate(string addr){
    string token;
    int num = 0;
    char ch;
    for(int i=0;i<addr.length();i++){
        ch = addr[i];
        if((ch>='0')&&(ch<='9')){
            token += ch;
        }else{
            if(num<3){
                if(ch!='.')return false;
            }else if(num==3){
                if(ch!=':')return false;
            }else{//too many fields!
//                cout << "TOO MANY FIELDS";
                return false;
            }
            if(!token.length()){
                return false;
            }
            if((token[0]=='0')&&(token.length()>1)){//redundant leading zero
//                cout << "RED.Ld.0" << token;
                return false;
            }
            int numerify = 0;
            int mult = 1;
            for(int x=token.length()-1;x>=0;x--){
                if((token[x]<'0')||(token[x]>'9')){
//                    cout << "Inv.No." << token;
                    return false;
                }
                numerify += mult*(token[x]-'0');
                mult *= 10;
            }
            if(numerify>255){
                return false;
            }
            num++;
            token = "";
        }
    }
    int numerify = 0;
    int mult = 1;
    if(!token.length()){
        return false;
    }
    if((token[0]=='0')&&(token.length()>1)){//redundant leading zero
//        cout << "RED.Ld.0" << token;
        return false;
    }
    for(int x=token.length()-1;x>=0;x--){
        if((token[x]<'0')||(token[x]>'9')){
//            cout << "Inv.No." << token;
            return false;
        }
        numerify += mult*(token[x]-'0');
        mult *= 10;
    }
    return numerify<65536;
}
map<string,int> machines;
int main(){
    freopen("network.in","r",stdin);
    freopen("network.out","w",stdout);
    int n;
    string t,addr;
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> t >> addr;
        if(!validate(addr)){
            cout << "ERR" << endl;
            continue;
        }
        if(t=="Server"){
            if(machines.count(addr)){
                cout << "FAIL" << endl;
                continue;
            }
            cout << "OK" << endl;
            machines[addr] = i;
        }else if(t=="Client"){
            if(!machines.count(addr)){
                cout << "FAIL" << endl;
                continue;
            }
            cout << machines[addr] << endl;
        }
    }
    return 0;
}
/*
5
Server 192.168.1.1:8080
Server 192.168.1.1:8080
Client 192.168.1.1:8080
Client 192.168.1.1:80
Client 192.168.1.1:99999
*/
